// =====================================================================================
// 
//       Filename:  array.cpp
// 
//    Description:  
// 
//        Version:  1.0
//        Created:  07.10.2011 14:38:18
//       Revision:  none
//       Compiler:  g++
// 
//         Author:  Dmitriy Serdyuk (), serdyuk.dmitriy@gmail.com
//        Company:  
// 
// =====================================================================================

#include "array.h"

Array::Array(size_t size) {
    mySize = size;
    myData = new int[mySize]; 
}

int Array::get(size_t index) const {
    if (index < 0 || index > mySize) {
        return -1;
    } 
    return myData[index];
}

void Array::set(size_t index, int v) {
    if (index < 0 || index > mySize) {
        return;
    }
    myData[index] = v;
}

Array &Array::operator=(const Array &ar) {
    if (&ar == this) {
        return *this;
    }
    delete[] myData;
    myData = new int[ar.mySize];
    mySize = ar.mySize;
    for (size_t i = 0; i < ar.mySize; ++i) {
        myData[i] = ar.get(i);
    }
    return *this;
}

Array::Array(const Array &ar) {
    myData = new int[ar.mySize];
    mySize = ar.mySize;
    for (size_t i = 0; i < ar.mySize; ++i) {
        myData[i] = ar.get(i);
    }
}

Array::~Array() {
    delete[] myData;
}

